package it.kion.util.ui.ulog2.views.actions;

import it.kion.util.ui.ulog2.Log4jPlugin;
import it.kion.util.ui.ulog2.views.Log4jDetailDialog;

import java.util.List;

import org.apache.log4j.spi.LoggingEvent;
import org.eclipse.jface.action.Action;
import org.eclipse.swt.widgets.Table;

public class ShowDetailAction extends Action {

	private Table table; 
	
	public ShowDetailAction(Table table) {
		this.table = table;		
	}

	public void run() {
		if(table!=null && table.getSelectionIndex()!=-1){
			int index = table.getSelectionIndex();
			LoggingEvent le = ((List<LoggingEvent>)Log4jPlugin.getDefault().getLoggingModel().getValidLogs()).get(index);
			Log4jDetailDialog dialog = new Log4jDetailDialog(table.getParent().getShell(), le);
			dialog.open();
		} else {
			table = Log4jPlugin.getMainView().getTable();
		}
	}
	
}
